package com.feign.feignClient;

import com.feign.feignClient.client.AnnotationClient;
import com.feign.feignClient.client.InterceptorClient;
import com.feign.feignClient.client.PlusClient;
import com.feign.feignClient.contract.MyContract;
import com.feign.feignClient.entity.Person;
import com.feign.feignClient.interceptor.MyInterceptor;
import feign.Feign;
import feign.Logger;
import feign.gson.GsonEncoder;
import feign.jaxrs.JAXRSContract;
import org.omg.CORBA.PUBLIC_MEMBER;

public class Test2 {

    public static void main(String [] args){
        System.out.println( );
        testPlus();
        System.out.println( );
        testAnnotation();
        System.out.println( );
        testInterceptor();
        System.out.println( );
        testLog();
    }


    public static void testPlus(){
        System.out.println(" -----test 第三方注解插件 ------ ");
        PlusClient plus = Feign.builder()
                .contract(new JAXRSContract())  //使用第三方注解翻译器
                .target(PlusClient.class, "http://localhost:8080/");
        System.out.println(plus.hello());
    }


    public static void testAnnotation(){
        System.out.println(" -----test 自定义注解插件 ------ ");
        AnnotationClient helloClient = Feign.builder()
                .contract(new MyContract())    //使用自定义注解翻译器
                .target(AnnotationClient.class, "http://localhost:8080/");
        String result = helloClient.sayHello();
        System.out.println( result);
    }



    public static void testInterceptor(){
        System.out.println(" -----test 自定义拦截器 ------ ");
        InterceptorClient client = Feign.builder().encoder(new GsonEncoder())
                .requestInterceptor(new MyInterceptor())   //自定义拦截器
                .target(InterceptorClient.class, "http://localhost:8080/");
        Person p = new Person();
        p.setName("test");
        p.setId(5L);
        System.out.println( client.personSaveJson(p));
    }


    public static void testLog(){
        System.out.println(" -----test 接口日志 ------ ");
        PlusClient plus = Feign.builder()
                .logLevel(Logger.Level.FULL)
                .logger(new Logger.JavaLogger().appendToFile("G:/http.log"))
                .contract(new JAXRSContract())  //使用第三方注解翻译器
                .target(PlusClient.class, "http://localhost:8080/");
        System.out.println(plus.hello());
    }


}
